package com.ytktt.study.week8.task6.shardingsphere.atomikosxa;

import com.ytktt.study.week8.task6.shardingsphere.atomikosxa.entity.order.OrderInfoEntity;
import com.ytktt.study.week8.task6.shardingsphere.atomikosxa.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.math.BigDecimal;

/**
 * 数据分片测试项目启动器
 *
 * @author ytk
 */
@Slf4j
@SpringBootApplication
@MapperScan("com.ytktt.study.week8.task6.shardingsphere.atomikosxa.mapper")
public class ShadingSphereAtomikosXAApplication implements ApplicationRunner {

    @Autowired
    private OrderService orderService;

    public static void main(String[] args) {
        SpringApplication.run(ShadingSphereAtomikosXAApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        long now = System.currentTimeMillis();
        OrderInfoEntity orderInfoEntity = new OrderInfoEntity();
        orderInfoEntity.setUserId(1);
        orderInfoEntity.setItemId(1);
        orderInfoEntity.setItemPrice(new BigDecimal(20));
        orderInfoEntity.setAmount(20);
        orderInfoEntity.setOrderPrice(new BigDecimal(40));
        orderInfoEntity.setDelFlag((byte) 0);
        orderInfoEntity.setStatus((byte) 1);
        orderInfoEntity.setCreateTime(now);
        orderInfoEntity.setUpdateTime(now);
        this.orderService.createOrder(orderInfoEntity);
    }
}
